package org.tc.product.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tc.product.entity.Joincommoditys;
import org.tc.product.mapper.JoincommoditysMapper;
import org.tc.product.service.JoincommoditysService;
import org.tc.product.util.PageHelper;

import java.util.Date;
import java.util.List;

@Service
@RestController
public class JoincommoditysServiceImpl implements JoincommoditysService {

    @Autowired
    private JoincommoditysMapper joincommoditysMapper;

    @Override
    public int insertJoin(@RequestBody Joincommoditys record) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String da = sdf.format(new Date());
        record.setJointime(new Date());
        int count = joincommoditysMapper.insertJoin(record);
        return count;
    }

    @Override
    public PageHelper<Joincommoditys> selectAllJoin(int pageNo, int pageSize, Integer storeid) {
        PageHelper<Joincommoditys> pageHelper = new PageHelper<>();
        pageHelper.setPageNo(pageNo);
        pageHelper.setPageSize(pageSize);
        List<Joincommoditys> slist = joincommoditysMapper.selectAllJoin(pageHelper.getFirstResult(), pageHelper.getPageSize(), storeid);
        pageHelper.setData(slist);
        int sumCount = joincommoditysMapper.getJoinCount(storeid);
        int pageCount = sumCount % pageSize == 0 ? sumCount / pageSize : sumCount / pageSize + 1;
        pageHelper.setPageCount(sumCount);
        return pageHelper;
    }

    @Override
    public List<Joincommoditys> QueryMonthJoon(String starttime,
                                               String jointime,
                                               Integer storeid) {

        return joincommoditysMapper.QueryMonthJoin(starttime, jointime, storeid);
    }

    @Override
    public List<Joincommoditys> QueryDayJoin(String jointime, Integer storeid) {
        return joincommoditysMapper.QueryDayJoin(jointime, storeid);
    }

    @Override
    public int QueryCountJoin(String starttime, String jointime, Integer storeid) {
        return joincommoditysMapper.QueryCountJoin(starttime, jointime, storeid);
    }

    @Override
    public int QueryDayCountJoin(String jointime, Integer storeid) {
        return joincommoditysMapper.QueryDayCountJoin(jointime, storeid);
    }



}
